﻿
/*
 * 模板方法模式：利用继承的特点把所以重复的代码提升到父类中，通过继承的方式复用代码
 * 而不是每个子类都去重复，这也是多态的一种体现
 * 当我们要完成再某一细节层次一直的一个过程或一系列步骤，
 * 但其某个步骤再更详细的实现层次上的实现可能不同时，我们可以考虑用模板方法来处理
 * 
 */
father father;
Ifather ifather;

father = new son1();
father.read();
ifather = new son1();
ifather.read();
ifather.read("dddddddd");
father = new son2();
father.read();
ifather = new son2();
ifather.read();
ifather.read("dddddddd");

interface Ifather
{
    public  void read();

    public  void write();

    public void read(string n);
}

abstract class father
{
    public abstract  void read();

    public abstract void write();  
    
}
class son1 : father, Ifather
{
    public override void read()
    {
        Console.WriteLine("son1_read");
    }

    public void read(string n)
    {
        Console.WriteLine(n);
    }

    public override void write()
    {
        Console.WriteLine("son1_write");
    }
}
class son2 : father,Ifather
{
    public override void read()
    {
        Console.WriteLine("son2_read");
    }

    public void read(string n)
    {
        Console.WriteLine(n);
    }

    public override void write()
    {
        Console.WriteLine("son2_write");
    }
}